package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理相关接口")
public class NursingLevelController extends BaseController{

    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation("获取所有护理等级")
    public ResponseResult getAll() {
        List<NursingLevelVo> nursingLevelVoList = nursingLevelService.getAll();
        return ResponseResult.success(nursingLevelVoList);
    }

    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult insert(@ApiParam(value = "护理等级数据传输对象") @RequestBody NursingLevelDto nursingLevelDto) {
        log.info("护理等级数据：nursingLevelDto:{}", nursingLevelDto);

        // 调用Service层方法
        nursingLevelService.insert(nursingLevelDto);

        return ResponseResult.success();
    }

    @GetMapping("/listByPage")
    @ApiOperation("护理等级-条件分页查询")
    public ResponseResult<NursingProjectVo> getByPage(
            @ApiParam("护理等级名称") String name,
            @ApiParam("状态（0：禁用，1：启用）") Integer status,
            @ApiParam("当前页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("每页显示数量") @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        log.info("查询护理等级列表，参数：name:{},status:{},pageNum:{},pageSize:{}", name, status, pageNum, pageSize);

        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.getByPage(name, status, pageNum, pageSize);

        return ResponseResult.success(pageResponse);
    }

    @GetMapping("/{id}")
    @ApiOperation("护理等级-根据ID查询")
    public ResponseResult getById(@ApiParam("护理等级ID") @PathVariable Integer id) {
        log.info("根据ID查询，参数：id:{}", id);
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation("护理等级-更新护理等级数据")
    public ResponseResult update(@ApiParam("护理等级数据传入对象") @RequestBody NursingLevelDto nursingLevelDto) {
        log.info("更新护理等级数据：nursingLevelDto:{}", nursingLevelDto);
        // 调用Service层方法
        nursingLevelService.update(nursingLevelDto);
        // 返回结果
        return ResponseResult.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult delete(@ApiParam("护理等级ID") @PathVariable Integer id) {
        log.info("删除护理等级，参数：id:{}", id);
        // 调用Service层方法
        nursingLevelService.delete(id);
        // 返回结果
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用状态")
    public ResponseResult updateStatus(@ApiParam("护理等级ID") @PathVariable Integer id, @ApiParam("状态（0：禁用，1：启用）") @PathVariable Integer status) {
        nursingLevelService.updateStatus(id, status);
        return success();
    }
}
